<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    import="java.io.PrintWriter, java.sql.ResultSet,
    		cn.edu.nju.software.model.user.Store,
    		cn.edu.nju.software.model.administrator.DisplayManager" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
	String username = (String) application.getAttribute("username");
	if (username == null || username.equals("")) {
		PrintWriter printWriter = response.getWriter();
		printWriter.println("<script>alert('Please login first!');"
						+ "window.location.href='../index.jsp';</script>");
	}
%>

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link type="text/css" rel="stylesheet" href="../css/index_header_footer.css" />
	<link type="text/css" rel="stylesheet" href="../css/index_sidebar.css" />
	<link type="text/css" rel="stylesheet" href="../css/user/booking.css" />
	<title>Hello <%= username %>, Booking your tickets</title>
</head>

<body>

	<div id="header">
		
		<div id="login">
			Hello, <%= username %>&nbsp;!&nbsp;&nbsp;&nbsp;
			<a href="../index.jsp">退出</a>
		</div>
		
		<div id="menu">
			<a href="home.jsp"><img src="../images/menu_homepage.png" alt="首页" /></a>
			<a href="vip.jsp"><img src="../images/menu_vip.png" alt="VIP专区" /></a>
			<a href="booking.jsp"><img src="../images/menu_booking.png" alt="优先购票" /></a>
			<a href="information.jsp"><img src="../images/menu_information.png" alt="个人资料" /></a>
		</div>
		
	</div>
	
	<div id="sidebar">
		
		<div id="activity" class="sidebar_cell">
			<a href="" class="sidebar_cell_link">更多--&gt;</a>
			<span class="sidebar_cell_title">影城活动</span>
			<div id="activity_list">
				<ul>
					<li><a href="">春节优惠活动</a></li>
					<li><a href="">看《最强喜事》，拿“百元”现金红包“</a></li>
					<li><a href="">新年影城”春联“征集，获胜优秀作品</a></li>
					<li><a href="">影城2月影讯</a></li>
					<li><a href="">好礼相送，幸运抽奖</a></li>
					<li><a href="">新春”春联“征集”</a></li>
				</ul>
			</div>
		</div>
		
		<div id="information" class="sidebar_cell">
			<a href="" class="sidebar_cell_link">更多--&gt;</a>
			<span class="sidebar_cell_title">新片资讯</span>
			<div class="movie_info_column">
				<p>
					<a href=""><img src="../images/movie/old_boy.jpg" /></a>
					<br />
					<a href="">老男孩</a>
					<br />
					<a href=""><img src="../images/movie/inception.jpg" /></a>
					<br />
					<a href="">盗梦空间</a>
				</p>
			</div>
			<div class="movie_info_column">
				<p>
					<a href=""><img src="../images/movie/if_you_are_the_one_2.jpg" /></a>
					<br />
					<a href="">非诚勿扰2</a>
					<br />
					<a href=""><img src="../images/movie/bullet_fly.jpg" /></a>
					<br />
					<a href="">让子弹飞</a>
				</p>
			</div>
		</div>
		
		<div id="poll" class="sidebar_cell">
			<span class="sidebar_cell_title">网上调查</span><br />
			<div id="poll_option">
				你最喜欢影院组织的哪些活动？
				<form>
					<p>
						<input type="checkbox" name="favor[]" value="discount" />观看影片及卖品的优惠<br />
						<input type="checkbox" name="favor[]" value="meeting" />影片主创及明星见面会<br />
						<input type="checkbox" name="favor[]" value="exhibition" />经典影片回顾展<br />
						<input type="submit" value="投票" />
					</p>
				</form>
			</div>
		</div>
		
	</div>
	
	<div id="content">
		<div>
			<a href="store.jsp" class="sidebar_cell_link">查看我的订单</a>
		</div>
		
		<div class="cell_title">订票</div>
		<form method="post" action="../Booking.do">
			<table>
				<tr>
					<th>放映室</th>
					<th>影片</th>
					<th>时间</th>
					<th>剩余票数</th>
					<th>票价</th>
					<th>预订票数</th>
				</tr>
				<%
				DisplayManager displayManager = new DisplayManager();
				ResultSet rs = displayManager.fetchAllDisplays();
				if (rs != null) {
					while (rs.next()) {
						int status = Integer.parseInt(rs.getString(6));
						if (status == 1){
							String hall = rs.getString(2);
							String movie = rs.getString(3);
							String time = rs.getString(4);
							String[] times = time.split("[/:-]");
							String minute = times[3];
							if (minute.length() == 1) {
								minute = "0" + minute;
							}
							String time_str = times[0] + "月 " + times[1] + "日 " + times[2] + ":" + minute;
							int surplus = rs.getInt(7);
							int price = rs.getInt(8);
							
							int row = rs.getRow();
							if (row % 2 == 0) {
								%>
								<tr class="color_row">
									<td><%= hall %></td>
									<td><%= movie %></td>
									<td><%= time_str %></td>
									<td><%= surplus %></td>
									<td><%= price %></td>
									<td><input type="text" name=<%= hall+"/"+movie %> value="0" />张</td>
								</tr>
								<%
							} else {
								%>
								<tr>
									<td><%= hall %></td>
									<td><%= movie %></td>
									<td><%= time_str %></td>
									<td><%= surplus %></td>
									<td><%= price %></td>
									<td><input type="text" name=<%= hall+"/"+movie %> value="0" />张</td>
								</tr>
								<%
							}
						}
					}
				}
				%>
				<tr>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td>
						<input type="submit" value="预订" />
						<input type="reset" value="重新填写" />
					</td>
				</tr>
			</table>
		</form>
	</div>
	
	
	<div id="footer">
		<p>
			Copyright &copy; <a href="mailto:zyy08@software.nju.edu.cn">张迎亚</a>·南京大学·软件学院·2011春节
		</p>
	</div>
	
</body>
</html>